import { createStore } from 'vuex'

// 模拟接口获取数据
function fetchItem(id) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        id,
        title: 'title' + id,
      })
    }, 300)
  })
}

export default () => {
  return createStore({
    state() {
      return {
        items: {},
		sessionId: '',
		token: '',
      }
    },
    actions: {
      fetchItem({ commit }, id) {
        return fetchItem(id).then((item) => {
          commit('setItem', { id, item })
        })
      },
	  setCollectionCursor({ commit }, cursor) {
		  
	  },
	  setSessionId({ commit}, id) {
		commit('set_sessionId', { id })
	  },
	  setToken({commit}, token) {
	  	commit('set_token', { token })
	  },
	  removeToken({ commit}) {
	  	commit('remove_token')
	  },
	  
    },
    mutations: {
      setItem(state, { id, item }) {
        state.items[id] = item
      },
	  set_sessionId(state, { id }) {
		console.log(id, 'id..')
	    state.sessionId = id
	  },
	  set_token(state, { token }) {
	  	console.log(token, 'token..')
	    state.token = token
	  },
	  remove_token(state){
		  state.token=''
		  console.log('token无')
	  },
    },
  })
}

